package com.thejoyrun.retrofit.utils;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * Created by kkmike999 on 2016/05/08.
 *
 * 读取 单元测试 本地Assets数据
 */
public class AssestsReader {

	/**
	 * @param path assets目录下，相对路径
	 * @return
	 * @throws IOException
	 */
	public static String readFile(String path) throws IOException {

		File file = new File("./src/test/assets/", path);

		FileReader fileReader = new FileReader(file);

		char[] chars = new char[1024];

		StringBuilder sb = new StringBuilder();

		int hasRead;

		while ((hasRead = fileReader.read(chars)) > -1) {
			sb.append(chars, 0, hasRead);
		}

		return sb.toString();
	}

//	@Test
//	public void readFile() throws IOException {
//		System.out.println(AssestsReader.readFile("success.json"));
//	}
}
